package java基础.array;

import java.util.Arrays;

/**
 * @author IT_Jay
 * @date 2022/1/21 18:58
 */

public class arrayDemo06 {
    public static void main(String[] args) {
        int[] a = {1, 2, 4, 5456, 67777, 9999, 6, 8};
        System.out.println(a);      //[I@776ec8df

        //打印数组
        System.out.println(Arrays.toString(a));
        //调用自定义方法实现同样效果
        printArray(a);


        Arrays.sort(a);     //对数组进行排序
        System.out.println("\n"+Arrays.toString(a));        //打印排序后数组


        Arrays.fill(a,0);       //数组填充
        System.out.println(Arrays.toString(a));
        Arrays.fill(a,2,4,9);       //将下标2到3的元素填充为9   注意：左闭右开：[2,4)
        System.out.println(Arrays.toString(a));

    }

    //也可以自己定义方法，打印数组
    public static void printArray(int[] a) {
        for (int i = 0; i < a.length; i++) {
            if (i == 0) System.out.print("[");
            if (i == a.length - 1) {
                System.out.print(a[i] + "]");
            } else {
                System.out.print(a[i] + ", ");
            }
        }
    }
}
